package ve.lm.hrms_cy.Controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ve.lm.hrms_cy.Entity.*;
import ve.lm.hrms_cy.Entity.Request.DepartmentQueryRequest;
import ve.lm.hrms_cy.Entity.Request.EmployeeQueryRequest;
import ve.lm.hrms_cy.Entity.Request.UserQueryRequest;
import ve.lm.hrms_cy.Entity.Response.ResponseEntityCY;
import ve.lm.hrms_cy.Service.SystemManagerService;

@RestController
@RequestMapping("/systemManager")
public class SystemManagerController {


    @Autowired
    SystemManagerService systemManagerService;


    @PostMapping("/userManager/findUserByPage")
    public ResponseEntityCY<IPage<User>> findUserByPage(@RequestBody UserQueryRequest userQueryRequest){

        IPage<User> pageResult = systemManagerService.findUserByPage(userQueryRequest);

        if(pageResult.getTotal()==0)
            return new ResponseEntityCY<>("200",true,pageResult,"查询成功！但没完全成功！");

        return new ResponseEntityCY<>("200",true,pageResult,"查询成功！");

    }

    @PostMapping("/userManager/addUser")
    public ResponseEntityCY<Boolean> addUser(@RequestBody User user){


            return systemManagerService.addUser(user);

    }

    @PostMapping("/userManager/updateUser")
    public ResponseEntityCY<Boolean> updateUser(@RequestBody User user){

        System.out.println(user.getName());

        return systemManagerService.updateUser(user);

    }

    @PostMapping("/userManager/deleteOrRecoverUser")
    public ResponseEntityCY<Boolean> deleteUser(@RequestParam("id") Long id,@RequestParam("isDelete") Boolean isDelete){

            return systemManagerService.deleteOrRecoverUser(id,isDelete);

    }

    @PostMapping("/employeeManager/addEmployee")
    public ResponseEntityCY<Boolean> addEmployee(@RequestBody Employee employee){

        return systemManagerService.addEmployee(employee);

    }

    @PostMapping("/employeeManager/findEmployeeByPage")
    public ResponseEntityCY<IPage<Employee>> addEmployee(@RequestBody EmployeeQueryRequest employeeQueryRequest){

        return systemManagerService.findEmployeeByPage(employeeQueryRequest);

    }

    @PostMapping("/employeeManager/updateEmployee")
    public ResponseEntityCY<Boolean> updateEmployee(@RequestBody Employee employee){

        return systemManagerService.updateEmployee(employee);

    }
    @PostMapping("/departmentManager/addDepartment")
    public ResponseEntityCY<Boolean> addDepartment(@RequestBody Department department){

        return systemManagerService.addDepartment(department);

    }

    @PostMapping("/departmentManager/findDepartmentByPage")
    public ResponseEntityCY<IPage<Department>> findDepartmentByPage(@RequestBody DepartmentQueryRequest departmentQueryRequest){

        return systemManagerService.findDepartmentByPage(departmentQueryRequest);

    }

    @PostMapping("/departmentManager/updateDepartment")
    public ResponseEntityCY<Boolean> updateDepartment(@RequestBody Department department){

        return systemManagerService.updateDepartment(department);

    }

    @PostMapping("/departmentManager/deleteOrRecoverDepartment")
    public ResponseEntityCY<Boolean> deleteOrRecoverDepartment(@RequestParam("id") Long id ,@RequestParam("isDelete") Boolean isDelete){

        return systemManagerService.deleteOrRecoverDepartment(id,isDelete);

    }

    @PostMapping("/userManager/findUserById")
    public ResponseEntityCY<User> findUserById(@RequestParam("id") Long id){

        return systemManagerService.findUserById(id);

    }

    @PostMapping("/userManager/updatePassword")
    public ResponseEntityCY<Boolean> updatePassword(@RequestParam("id") Long id,@RequestParam("oldPassword") String oldPassword ,@RequestParam("newPassword") String newPassword){

        return systemManagerService.updatePassword(id,oldPassword,newPassword);

    }







}
